<template>
	<view  style="background: #F1F1F1;height: 100vh;">
		<view style="background: #fff;padding: 0 30rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="车牌" prop="cn" label-width="200">
					<u-input v-model="form.cn" disabled  type="select" placeholder="请选择车牌" @click='iscn=true'/>
				</u-form-item>
				<u-form-item label="年审时间" prop="stare" label-width="200">
					<u-input v-model="form.stare" disabled  @click="show=true,isStare=true" placeholder="请选择年审时间"/>
				</u-form-item>
				<u-form-item label="年检时间" prop="end" label-width="200">
					<u-input v-model="form.end" disabled  @click="show=true,isStare=false" placeholder="请选择年检时间"/>
				</u-form-item>
			</u-form>
		</view>
		
		<u-picker v-model="show" mode="time" @confirm="sure"></u-picker>
			<u-select v-model="iscn" :list="list" value-name="cn" label-name="cn" @confirm="surecn"></u-select>
		
		<u-button @click="submit" :custom-style="{background:'#1B8AF6',color:'#fff',width:'90%',margin:'30rpx auto'}">提交</u-button>
	<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			show:false,
			isStare:'',
			iscn:false,
			form: {
				cn:"",
				stare: '',
				end: '',
			},
			list:[],
			rules: {
				cn: [
					{ 
						required: true, 
						message: '请选择车牌', 
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change','blur'],
					}
				],
				stare: [
					{ 
						required: true, 
						message: '请输入年审时间', 
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change','blur'],
					}
				],
				end: [
					{
						required: true, 
						message: '请输入年检时间', 
						trigger: ['change','blur'],
					}
				]
			}
		};
	},
	methods: {
		submit() {
			this.$refs.uForm.validate(valid => {
				if (valid) {
					this.$u.post('/api/user/remind', {
						cn:this.form.cn,
					     nj_date:this.form.stare,
						 bx_date:this.form.end
					}).then(res => {
					   
					   this.$refs.uToast.show({
					   	title: '提醒审核',
					   	type: 'success',
					     back :true
					   })
					}).catch(err => {
					
					})
				} else {
					console.log('验证失败');
				}
			});
		},
		sure(e){
			if(this.isStare){
				this.form.stare= this.$u.timeFormat(e.timestamp,'yyyy-mm-dd') 
			}else{
				this.form.end= this.$u.timeFormat(e.timestamp,'yyyy-mm-dd') 
			}
		},
		surecn(e){
			this.form.cn=e[0].value;
		},
		getcn(){
			this.$u.post('/api/user/cn', {}).then(res => {
				this.list = res;
				if(!res.length){
					this.$refs.uToast.show({
						title: '暂无车牌,请绑定车牌',
						type: 'success',
					  callback :()=>{
						  uni.navigateTo({
						  	url:"../bindCar/index"
						  })
					  }
					})
				}
			}).catch(err => {})
			
		}
	},
	onLoad(options) {
		if(options.txt){
			let {cn,njDate,bxDate }=JSON.parse(options.txt);
		
			this.form.cn=cn;
			this.form.stare=njDate;
			this.form.end=bxDate;
			
		}
	},
	// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},
	onShow() {
		this.getcn()
	}
};
</script>
